

import axios from "axios"
const request=axios.create({
    baseURL:process.env.VUE_APP_BASEURL,
    timeout:30000
})

request.interceptors.request.use(config=>{
    config.headers['Content-Type']='application/json;charset=utf-8';
    let user=JSON.parse(localStorage.getItem("user"||'{}'))
    if(user!=null)
    config.headers['token']=user.token

    return config
},error=>{
    this.$message.error("网络请求超时")
    console.error('request error:' +error)
    return Promise.reject(error)
});

request.interceptors.response.use(
    response =>{
        let res=response.data;
        if(typeof res==='string'){
            res=res?JSON.parse(res) : res;
        }
        return res;
    },
    error=>{
        console.error('response error:'+error)
        return Promise.reject(error)
    }


)

export default request